let box = document.querySelector(".box")
let userName = document.querySelector("#un")
let password = document.querySelector("#mm")
let sub = document.querySelector("#sub")
let reg = document.querySelector("#reg")
let ts = document.querySelector(".ts")
let mmts = document.querySelector(".mmts")
//非空判断
function judgeIsNull() {
    userName.addEventListener("blur", function () {
        if (!userName.value) {
            ts.classList.add("active")
            return
        } else {
            ts.classList.remove("active")
        }
    })
    password.addEventListener("blur", function () {
        if (password.value == "") {
            mmts.classList.add("active")
            return
        } else {
            mmts.classList.remove("active")
        }
    })
}
judgeIsNull()

function submit() {
    //获取用户输入的数据
    sub.addEventListener("click", function () {

        // 获取localstorage中的数据
        let productListStr = localStorage.getItem('USERLIST')
        let productList = JSON.parse(productListStr) || []


        let names = userName.value
        let psds = password.value

        myPromise({
            method: 'post',
            url: 'http://api.yuguoxy.com/api/member/login',
            data: {
                username: names,
                password: psds
            }
        }).then(function (data) {
            if (data.resultCode == 1) {
                alert("登录成功")
                let LINSHI = []
                LINSHI.push(data.resultInfo)
                let dataInfo = JSON.stringify(LINSHI)
                localStorage.setItem('LINSHI', dataInfo)
                window.location.href = "index.html"
            }
        })

    })

}


//注册
function register() {
    reg.addEventListener("click", function () {
        window.location.href = "register.html"
    })
}
register()
submit()